new Vue({
    el:".container",
    data:{
        limitNum:3,
        addressShow:false,
        addressList:[],
        currentIndex:0,
        shippingMethod:1,
        isShow:false,
        showModalw:false,
        curProduct:'',
    },
    mounted:function () {
        this.$nextTick(function () {
            this.createView();
        });
    },
    computed:{
        filterAddress:function () {
            return this.addressList.slice(0,this.limitNum);//截取数组，返回一个全新的数组
        }
    },
    methods:{
        //绑定数据
        createView:function () {
            this.$http.get('data/address.json').then(res=>{
                var res = res.data;
                if(res.status == "0"){
                    this.addressList = res.result;
                }
            });
        },
        //显示地址、隐藏地址
        loadMore:function () {
            this.addressShow = !this.addressShow;
            if(this.addressShow){
                this.limitNum = this.addressList.length;
            }else {
                this.limitNum = 3;
            }
        },
        //设置默认地址
        setDefault:function (addressId) {
            this.addressList.forEach(function (address,index) {
                if(address.addressId == addressId){
                    address.isDefault = true;
                }else{
                    address.isDefault = false;
                }
            })
        },
        isDelShow:function (item) {
            this.isShow = true;
            this.curProduct = item;
        },
        addressDel:function () {
            var index = this.addressList.indexOf(this.curProduct);
            this.addressList.splice(index,1);
            this.isShow = false;
        },
        addAddress:function(){
            this.showModalw = true;
        }
    },

});